﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Newtonsoft.Json;
using Geometry;
using ReBot.API;


namespace ReBot
{
    [Rotation("Divine Shield v1.3", "Dupe", WoWClass.Priest, Specialization.PriestDiscipline, 20)]
    public class Divine_Shieldv130 : CombatRotation
    {
//
//Hello, and welcome to the Aphla for my first Discipline Priest, Utility Support healing rotation.
//name pending by Duplicate aka dupe
//
//Special thanks too, and credit reserved for:
//Vecelinus:- The script structure and allowing me to use his work as a template.
//Dalajin:- The Tank healing script.
//
//Target friendly to heal or target hostile to Dps.
//Switching between damage and healing pops archangel.
//May act funny/pause while mesh is loading, restart bot and reselect target if this happens.
//
//Will not Mind Sear Training Dummies as they class as neutral.
//
//
//
//
//
//------Settings Start
     //-- in game selection options
        [JsonProperty("Levitate? yes or no   ")]
        public bool levitate_player = false;
        [JsonProperty("Use Angelic Feather?  ")]
        public bool Use_AngelicFeather = false;
        [JsonProperty("Use Halo?             ")]
        public bool Use_Halo = false;
        [JsonProperty("Dispel Group?        ")]
        public bool Dispel_Group = false;
     //-- in game selection otions end

     //-- talent detection deffinition                    
        public bool Desperate_Prayer = false;
        public bool  Spectral_guise  = false;       
        public String AngelicBalwark = "Passive";     
        public String Body_and_soul = "Passive";
        public bool Angelic_Feather = false;     
        public bool Phantasm = false;      
        public String Surge_of_light = "Passive";       
        public bool Mindbender = false;       
        public bool Power_Word_Solace = false;    
        public bool Void_Tendrils = false;      
        public bool Psychic_Scream = false;      
        public String Dominate_Mind = "Not implemented";      
        public String Twist_of_Fate = "Passive";      
        public bool Power_Infusion = false;      
        public bool Spirit_Shell = false;     
        public bool Cascade_talent = false;      
        public bool Divine_Star = false;    
        public bool Halo_talent = false;
        public bool Clarity_of_Will = false;
        public String Words_of_Mending = "Passive";
        public bool Saving_Grace = false;
    //-- in game talent detection 
       
//------Settings Finish
    
        public bool Debug = true;
        
        //Writes to log
        private void DebugWrite(string text)
        {
            if (Debug) API.Print(text);
        }
       
        public Divine_Shieldv130()
		{
            //Tier 1 Talents Detected -----
            if (HasSpell(19236))//Desperate Prayer
            {
                Desperate_Prayer = true;
                DebugWrite("Desperate Prayer tier 1 = " + Desperate_Prayer);
            }
            else if (HasSpell(112833))//Spectual guise
            {
                Spectral_guise = true;
                DebugWrite("Specual guise Tier 1 = " + Spectral_guise);
            }
            //Tier 1 end
            //Tier 2 Detected ---------
            if (HasSpell(121536))//Angelic Feather
            {
                Angelic_Feather = true;
                DebugWrite("Angelic Feather tier 2 = " + Angelic_Feather);
            }
            else if (HasSpell(108942))//Phantasm
            {
                Spectral_guise = true;
                DebugWrite("Phantasm Tier 2 = " + Phantasm);
            }
            //Tier 2 end
            //Tier 3 Detected ----------
            if (HasSpell(123040))//Mindbender
            {
                Mindbender = true;
                DebugWrite("Mindbender Tier 3 = " + Mindbender);
            }
            else if (HasSpell(129250))//Powerword: Solace
            {
                Power_Word_Solace = true;
                DebugWrite("Power Word: Solace Tier 3 = " + Power_Word_Solace);
            }
            //Tier 3 end
            //Tier 4 Detected -------------
            if (HasSpell(108920))//Void Tendrils
            {
                Void_Tendrils = true;
                DebugWrite("Void Tendrils Tier 4 = " + Void_Tendrils);
            }
            
            //Tier 4 end
            //Tier 5 Detected -------------
            if (HasSpell(10060))//Power Infusion
            {
                Power_Infusion = true;
                DebugWrite("Power Infusion Tier 5 = " + Power_Infusion);
            }
            else if (HasSpell(109964))//Spirit Shell
            {
                Spirit_Shell = true;
                DebugWrite("Spirit Shell Tier 5 = " + Spirit_Shell);
            }
            //Tier 5 end
            //Tier 6 Detected -------------
            if (HasSpell(121135))//Cascade
            {
                Cascade_talent = true;
                DebugWrite("Cascade Tier 6 = " + Cascade_talent);
            }
            else if (HasSpell(110744))//Divine Star
            {
                Divine_Star = true;
                DebugWrite("Divine Star Tier 6 = " + Divine_Star);
            }
            else if (HasSpell(120517))//Halo
            {
                Halo_talent = true;
                DebugWrite("Halo Tier 6 = " + Halo_talent);
            }
            //Tier 6 end
            //Tier 7 Detected ------------
            if (HasSpell(152118))//Clarity of Will
            {
                Clarity_of_Will = true;
                DebugWrite("Clarity of Will Tier 7 = " + Clarity_of_Will);
            }
            else if (HasSpell(152116))//Saving Grace
            {
                Saving_Grace = true;
                DebugWrite("Saving Grace Tier 7 = " + Saving_Grace);
            }
            //Tier 7 end

			GroupBuffs = new string[]
			{
				"Power Word: Fortitude"
			};
			PullSpells = new string[]
			{
				"Smite",
			};
		}

//------------Tank bizz
        public bool Tank1Healing()
        {
            List<PlayerObject> members = Group.GetGroupMemberObjects();
            List<PlayerObject> GrpHeal1 = members.FindAll(x => x.HealthFraction <= 0.85 && x.IsInCombatRangeAndLoS && !x.IsDead);
            List<PlayerObject> Tanks = members.FindAll(x => x.IsTank);
            PlayerObject Tank1 = Tanks.FirstOrDefault();
            if (Tank1 != null)
            {
                if (Tank1.HealthFraction < 0.9)
                {
                    return true;
                }
            }
            return false;
        }
//------------Tank bizz end

//------------Combat Start----------
        public override bool OutOfCombat()
        {
            if (Me.IsMounted || Me.HasAura("Drink"))
            {
                DebugWrite("Paused while");
                return false;
            }
            else
            {

               // if (CastSelf("Power Word: Fortitude", () => !HasAura("Power Word: Fortitude"))) return true;

                //-----------------Angelic Feather Talent start
                if (Angelic_Feather == true && Use_AngelicFeather == true)
                {
                    AngelicFeather();
                }
                //------------------Angelic Feather talent end


                if (CurrentBotName == "Combat")
                {
                    List<PlayerObject> members = Group.GetGroupMemberObjects();
                    if (members.Count > 0 && !Me.IsMoving)
                    {
                        PlayerObject deadPlayer = members.FirstOrDefault(x => x.IsDead && x.DistanceSquared < 10 * 10);
                        if (Cast("Mass Resurrection", () => deadPlayer != null, deadPlayer)) return true;
                    }
                    
                }
                if (levitate_player == true)
                {
                    if (CastSelf("Levitate", () => Me.FallingTime > 2 && !HasAura("Levitate"))) return true;

                    // Only use OnWaterMove Spell, if Navi target is not in water. Cancel buff if we have to dive
                    if (API.GetNaviTarget() != Vector3.Zero && HasSpell("Levitate"))
                    {
                        if (!API.IsNaviTargetInWater())
                        {
                            if (CastSelf("Levitate", () => Me.Race != WoWRace.Tauren && Me.IsSwimming && !HasAura("Levitate"))) return true;
                        }
                        else if (HasAura("Levitate"))
                            CancelAura("Levitate");
                    }
                }
                List<PlayerObject> groupmembers = Group.GetGroupMemberObjects();
                List<PlayerObject> Tanks = groupmembers.FindAll(x => x.IsTank && x.IsInCombatRangeAndLoS);
                PlayerObject Tank1 = Tanks.FirstOrDefault();

                if (Tank1 != null && Tank1.InCombat && Me.Target != null)
                {
                    if (CastPreventDouble("Power Word: Shield", () => !Tank1.HasAura("Weakened Soul") && Tank1.IsInCombatRangeAndLoS && !Tank1.IsDead, Tank1, 1000)) return true;
                }
                 if (Me.Target != null && Me.HealthFraction <= 0.7 || Tank1 != null && Me.Target != null)
                {
                    Healer();
                    return true;
                }
                 Cast("Shadow Word: Pain", ()=> Me.HealthFraction > 0.7 && Me.Target != null && Me.Target.IsEnemy && !Me.Target.IsDead);
                return false;
               
                 }
        }
       

        public override void Combat()
        {

            

            if (!Target.IsEnemy || (Me.InCombat && Me.IsTargetingMeOrPets == true) || (CombatRole.Equals(CombatRole.DPS) && Me.Target == Me) || Me.Target.DisplayId == 49312)
                {
                    Healer();

                }
                else
                {
                    DPS();

                }
                //Dummy zapping
                if (Target.DisplayId == 28048 || Target.DisplayId == 27510)
                {
                    DPS();
                }
                
            
        }

        void Healer()
        {
            
            //*Global cooldown check
            if (HasGlobalCooldown())
            {
                return;
            }
            // Popping Archangel if possible
            CastSelf("Archangel", () => HasAura("Evangelism"));

            // setting group

            List<PlayerObject> members = Group.GetGroupMemberObjects();
            int membercount = members.Count + 1;

            if (membercount > 0)
            {

                // Finding Tank
                List<PlayerObject> Tanks = members.FindAll(x => x.IsTank && x.IsInCombatRange && !x.IsDead);
                PlayerObject Tank1 = Tanks.FirstOrDefault();


                // Group Healing
                if (Halo_talent == true && Use_Halo == true)
                {
                    Halo();
                }
                else if (Cascade_talent == true)
                {
                    Cascade();
                }

                List<PlayerObject> GrpHeal2 = members.FindAll(x => x.HealthFraction <= 0.7 && x.IsInCombatRange && !x.IsDead && x.Distance < 40);
                PlayerObject healtest = GrpHeal2.FirstOrDefault(x => !x.IsDead && x.IsInCombatRange);

                if (GrpHeal2.Count >= 2)
                {
                    if (Tank1 != null)
                    {
                        if (Tank1.HealthFraction > healtest.HealthFraction)
                        {
                            Cast("Prayer of Healing", GrpHeal2.First());
                            DebugWrite("Casting Payer of Healing");
                            return;
                        }
                        else
                        {
                            return;
                        }
                    }
                }
                Holy_Nova();
                
                if (Dispel_Group == true)
                {
                    List<PlayerObject> GrpCleanse = members.FindAll(m => m.IsInCombatRange && m.Auras.Any(a => a.IsDebuff && "Magic,Disease".Contains(a.DebuffType)));
                    DebugWrite("" + GrpCleanse);
                    if (GrpCleanse.Count > 3)
                    {
                        CastOnTerrain("Mass Dispel", GrpCleanse.First().Position);
                        DebugWrite("" + GrpCleanse);
                        return;
                    }
                    foreach (var emd in Group.GetGroupMemberObjects().Where(x => x.IsInCombatRange && x.Auras.Any(a => a.IsDebuff && "Magic,Disease".Contains(a.DebuffType))))
                    {
                        if (Cast("Purify", emd)) return;
                    }
                }
                

                // Shield Tank
                if (Tank1 != null)
                {
                    if (Cast("Power Word: Shield", () => !Tank1.HasAura("Weakened Soul") && !Tank1.HasAura("Power Word: Shield") && Tank1.IsInCombatRange && !Tank1.IsDead, Tank1))
                    {
                        DebugWrite("Shielding " + Tank1);
                    }
                    if (Cast("Prayer of Mending", () => !Tank1.HasAura("Prayer of Mending") && Tank1.IsInCombatRange && !Tank1.IsDead, Tank1))
                    {
                        DebugWrite("POM on " + Tank1);
                    }
                    if (Clarity_of_Will == true)
                    {
                        ClarityOfWill();
                    }
                    if (Divine_Star == true)
                    {
                        DivineStar();
                    }

                   
                }

                // Tank 1
                if (Tank1 != null)
                {
                    if (Tank1.IsInCombatRange)
                    {
                        if (Tank1.HealthFraction <= 0.3)
                        {
                            Cast("Flash Heal", () => Tank1.IsInCombatRange && !Tank1.IsDead, Tank1);
                            DebugWrite("Casting Flash Heal on " + Tank1);
                        }
                        else if (Tank1.HealthFraction <= 0.7 && !Me.HasAura("Saving Grace") && Saving_Grace == true && Tank1.IsInCombatRange)
                        {
                            Cast("Saving Grace",Tank1);
                        }
                        else if (Tank1.HealthFraction <= 0.7 && SpellCooldown("Pain Suppression") < 0)
                        {
                            Cast("Pain Suppression", () => Tank1.IsInCombatRange && !Tank1.IsDead && SpellCooldown("Pain Suppression") < 0, Tank1);
                            DebugWrite("Casting Pain Suppression on " + Tank1);
                        }
                        else if (Tank1.HealthFraction <= 0.8)
                        {
                            Cast("Heal", () => Tank1.IsInCombatRange && !Tank1.IsDead, Tank1);
                            DebugWrite("Casting Heal on " + Tank1);

                        }
                        else if (Tank1.HealthFraction <= 0.9 && SpellCooldown("Penance") < 0)
                        {
                            Cast("Penance", () => Tank1.IsInCombatRange && !Tank1.IsDead, Tank1);
                            DebugWrite("Casting Penance on " + Tank1);
                        }

                    }
                }

                // Tank 2
                if (Tanks.Count > 1)
                {
                    PlayerObject Tank2 = Tanks.Last();

                    if (Tank2 != null && Tank2.IsInCombatRange)
                    {


                        if (Cast("Power Word: Shield", () => !Tank2.HasAura("Weakened Soul") && !Tank2.HasAura("Power Word: Shield") && Tank2.IsInCombatRange && !Tank2.IsDead, Tank2))
                        {
                            DebugWrite("Shielding " + Tank2);
                        }
                        if (Cast("Prayer of Mending", () => !Tank2.HasAura("Prayer of Mending") && Tank2.IsInCombatRange && !Tank2.IsDead, Tank2))
                        {
                            DebugWrite("POM on " + Tank2);
                        }
                        if (Tank2.HealthFraction <= 0.3)
                        {
                            Cast("Flash Heal", () => Tank2.IsInCombatRange && !Tank2.IsDead, Tank2);
                            DebugWrite("Casting Flash Heal on " + Tank2);
                        }
                        else if (Tank2.HealthFraction <= 0.5 && !Me.HasAura("Saving Grace") && Saving_Grace == true && Tank2.IsInCombatRange)
                        {
                            Cast("Saving Grace", Tank2);
                        }
                        else if (Tank2.HealthFraction <= 0.7 && SpellCooldown("Pain Suppression") < 0)
                        {
                            Cast("Pain Suppression", () => Tank2.IsInCombatRange && !Tank2.IsDead, Tank2);
                            DebugWrite("Casting Pain Supression on " + Tank2);

                        }
                        else if (Tank2.HealthFraction <= 0.8)
                        {
                            Cast("Heal", () => Tank2.IsInCombatRange && !Tank2.IsDead, Tank2);
                            DebugWrite("Casting Heal on " + Tank2);

                        }
                        else if (Tank2.HealthFraction <= 0.9 && SpellCooldown("Penance") < 0)
                        {
                            Cast("Penance", () => Tank2.IsInCombatRange && !Tank2.IsDead, Tank2);
                            DebugWrite("Casting Penance on " + Tank2);

                        }
                    }
                    else
                    {
                        return;
                    }
                    //Second part of group healing, single target healing

                }

                foreach (var player in Group.GetGroupMemberObjects().Where(x => x.HealthFraction < 0.9 && x.IsInCombatRange))
                {
                    Cast("Power Word: Shield", player, () => !player.HasAura("Weakened Soul") && !player.HasAura("Power Word: Shield") && player.IsInCombatRange && !player.IsDead && SpellCooldown("Power Word: Shield") < 0);
                    Cast("Saving Grace", player, ()=> player.HealthFraction <= 0.5 && !Me.HasAura("Saving Grace") && Saving_Grace == true && player.IsInCombatRangeAndLoS);
                    Cast("Flash Heal", player, () => !player.IsTank && !player.IsDead && player.HealthFraction < 0.5 && !player.IsDead && !Me.IsCasting);
                    Cast("Penance", player, () => !player.IsTank && !player.IsDead && player.HealthFraction < 0.75 && !player.IsDead && !Me.IsCasting && SpellCooldown("Penance") < 0);
                    Cast("Heal", player, () => !player.IsTank && !player.IsDead && player.HealthFraction < 0.8 && player.HealthFraction > 0.4 && !player.IsDead && !Me.IsCasting);
                }
                //Healing me
                //------------Desperate prayer
                if (Desperate_Prayer == true)
                {
                    DesperatePrayer();
                }
                CastSelf("Power Word: Shield", () => !Me.HasAura("Weakened Soul") && !Me.HasAura("Power Word: Shield") && Me.HealthFraction < 0.99);
                CastSelf("Heal", () => Me.HealthFraction <= 0.9);
                CastSelf("Flash Heal", () => Me.HealthFraction <= 0.4);
                //------------Desperate Prayer end
                //Regen mana if low
                //------------Mindbender
                if (Mindbender == true)
                {
                    MindBender();
                }
                //------------Mindbender end
                if (Cast("Shadowfiend", () => Me.ManaFraction < 0.5 && Mindbender == false))
                {
                    DebugWrite("Low Mana Releasing Shadowfiend");
                    return;
                }
               
                

            }
        }

        void DPS()
        {
            //Global cooldown check
            if (HasGlobalCooldown())
                return;
            List<PlayerObject> members = Group.GetGroupMemberObjects();
            List<PlayerObject> GrpHeal1 = members.FindAll(x => x.HealthFraction <= 0.85 && x.IsInCombatRangeAndLoS && !x.IsDead);

            List<PlayerObject> Tanks = members.FindAll(x => x.IsTank && x.IsInCombatRange && !x.IsDead);
            PlayerObject Tank1 = Tanks.FirstOrDefault();
            if (Tank1 != null)
            {
                Cast("Power Word: Shield", () => !Tank1.HasAura("Weakened Soul") && !Tank1.HasAura("Power Word: Shield") && Tank1.IsInCombatRange && !Tank1.IsDead, Tank1);
            }

            if (!Me.Target.IsEnemy || Me.HealthFraction < 0.5 || GrpHeal1.Count >= 2 || Tank1Healing() == true)
            {
                Healer();
            }
            else if (Me.Target.IsEnemy && Me.HealthFraction > 0.5 && GrpHeal1.Count < 2 && Me.IsChanneling == false && Tank1Healing() == false)
            {
                if (HasGlobalCooldown())
                    return;
                //------------Power Word: Solace
                PowerWordSolace();
                //------------Power Word: Solace end
                //finding adds for Dots
                List<UnitObject> mobs = Adds.FindAll(x => x.DistanceSquared < SpellMaxRangeSq("Shadow Word: Pain") && x.IsEnemy);
                if (mobs.Count > 0)
                {

                    //Finds adds for SWpain dot
                    foreach (var SWpain in mobs.Where(x => !x.HasAura("Shadow Word: Pain") && x.IsEnemy))
                    {
                        //Dots mobs in range
                        UnitObject SWP = SWpain;
                        CastPreventDouble("Shadow Word: Pain", () => !SWP.IsDead && SWP.IsEnemy, SWP);

                        return;
                    }
                }

                //mana regen
                //-----------------Mindbender
                if (Mindbender == true)
                {
                    MindBender();
                }
                //-----------------Mindbender end
                if (Cast("Shadowfiend", () => Me.ManaFraction < 0.5)) return;
                //-------------Void Tendrils
                if (Void_Tendrils == true)
                {
                    VoidTendrils();
                }
                //-------------Void Tendrils end

                // attack rotation
                if (Cast("Penance", () => Target.IsEnemy)) return;
               
               
                
                Cast("Holy Fire", () => !Target.HasAura("Holy Fire") && SpellCooldown("Holy Fire") < 0 && Target.IsEnemy);
                Cast("Shadow Word: Pain", () => !Target.HasAura("Shadow Word: Pain") && Target.IsEnemy);
                List<UnitObject> MS = Adds.FindAll(x => x.DistanceSquaredTo(Target) < 10 * 10 && x.IsEnemy && x.HasAura("Shadow Word: Pain"));
                if (MS.Count >= 2 || Target.DisplayId == 28048)
                {
                    Mind_Sear();
                }
                
                if (Cast("Smite", () => Me.ChannelingSpellID != 48045 && !Me.IsCasting && Me.Target.IsEnemy)) return;
                
            }
        }

        //--------------Talent Start --------------      
        void DesperatePrayer() // Rotated in
        {
            if (CastPreventDouble("Desperate Prayer", () => Me.HealthFraction < 0.5 && !Me.IsCasting)) return;
        }
        void AngelicFeather() //Rotated in
        {
            if (CastOnTerrain("Angelic Feather", Me.PositionPredicted, () => Me.MovementSpeed > 0 && !HasAura("Angelic Feather"))) return;
        }
        void MindBender() //Rotated in
        {
            if (Cast("Mindbender", () => Me.ManaFraction < 0.5 && Me.Target.IsEnemy, Adds.FirstOrDefault()))
            {
                DebugWrite("Low Mana Casting Mindbender");
            }
        }
        void PowerWordSolace() //Rotated in
        {
            List<UnitObject> mobs = Adds.FindAll(x => x.DistanceSquared < SpellMaxRangeSq("Power Word: Solace") && x.IsEnemy);
            if (mobs.Count > 0)
            {
                //Solace CD Check
                if (SpellCooldown("Power Word: Solace") < 0)
                {

                    //Cast solace on add
                    var Solmob = mobs.FirstOrDefault();
                    CastPreventDouble("Power Word: Solace", () => !Solmob.IsDead && Solmob.IsInCombatRangeAndLoS && Me.Target.IsEnemy, Solmob);
                    DebugWrite("Casting Solace on " + Solmob + SpellCooldown("Power Word: Solace"));
                    return;
                }
            }

            if (Cast("Power Word: Solace")) return;
        }
        void VoidTendrils() //Rotated in
        {
            List<UnitObject> mobs = Adds.FindAll(x => x.DistanceSquaredTo(Target) < 10 * 10);
            if (CastPreventDouble("Void Tendrils", () => mobs.Count > 2, Adds.FirstOrDefault())) return;
        }
        void PsychicScream()
        {
            List<UnitObject> mobs = Adds.FindAll(x => x.DistanceSquaredTo(Me) < 8 * 8);
            if (CastPreventDouble("Psychic Scream", () => mobs.Count > 2)) return;
        }
        void DominateMind()
        {
            //No idea how to get this working at the min :D
        }
        void SpiritShell()
        {
            if (CastPreventDouble("Spirit Shell", () => !Target.IsEnemy && Target.HealthFraction < 0.9 && Target.IsInCombatRangeAndLoS && !Me.HasAura("Spirit Shell"))) return;
        }
        void Cascade()//Rotated in
        {
            List<PlayerObject> members = Group.GetGroupMemberObjects();
            if (members.Count > 0)
            {
                List<PlayerObject> GrpHeal1 = members.FindAll(x => x.HealthFraction <= 0.85 && x.IsInCombatRangeAndLoS && !x.IsDead);
                PlayerObject healtarget = GrpHeal1.FirstOrDefault();
                if (GrpHeal1.Count > 2)
                {
                    if (CastPreventDouble("Cascade", () => Target.HealthFraction < 0.9 && SpellCooldown("Cascade") < 0, healtarget)) return;
                }
            }
        }


        void DivineStar()//Rotated in
        {
            List<PlayerObject> members = Group.GetGroupMemberObjects();
            if (members.Count > 0)
            {
                // Finding Tank
                List<PlayerObject> Tanks = members.FindAll(x => x.IsTank && x.IsInCombatRangeAndLoS && !x.IsDead);
                PlayerObject Tank = Tanks.FirstOrDefault();
                if (Tank != null)
                {
                    Cast("Divine Start", () => !Tank.IsDead && Tank.HealthFraction < 0.8, Tank);
                    return;
                }
            }
        }
        void Halo()// Rotated in
        {
            List<PlayerObject> members = Group.GetGroupMemberObjects();
            if (members.Count > 0)
            {
                List<PlayerObject> GrpHeal1 = members.FindAll(x => x.HealthFraction <= 0.85 && x.IsInCombatRangeAndLoS && !x.IsDead && x.DistanceSquaredTo(Me) < SpellMaxRangeSq("Halo"));
                if (GrpHeal1.Count > 2)
                {
                    if (CastPreventDouble("Halo", () => Target.HealthFraction < 0.9 && SpellCooldown("Halo") < 0)) return;
                }
            }
        }
        void ClarityOfWill()
        {
            List<PlayerObject> members = Group.GetGroupMemberObjects();
            int membercount = members.Count + 1;

            if (membercount > 0)
            {

                // Finding Tank
                List<PlayerObject> Tanks = members.FindAll(x => x.IsTank && x.IsInCombatRange && !x.IsDead);
                PlayerObject Tank1 = Tanks.FirstOrDefault();
                if (Cast("Clarity of Will", ()=> Tank1.HealthMissing > 40000 && Me.Mana > 5000 && !Tank1.HasAura("Clarity of Will"), Tank1)) return;   
            }
        }
       
        //------------Talents End-----------

        //------------Holy Nova
        void Holy_Nova()
        {
            List<PlayerObject> members = Group.GetGroupMemberObjects();
            if (members.Count > 0)
            {
                List<PlayerObject> GrpHeal1 = members.FindAll(x => x.HealthFraction <= 0.85 && x.IsInCombatRangeAndLoS && !x.IsDead && x.DistanceSquaredTo(Me) < SpellMaxRangeSq("Holy Nova"));
                if (GrpHeal1.Count > 2)
                {
                    if (CastPreventDouble("Holy Nova", () => Target.HealthFraction < 0.9 && SpellCooldown("Holy Nova") < 0)) return;
                }
            }
        }

        //------------Holy Nova end
        void Mind_Sear()
        {
            Cast("Mind Sear", () => !Me.IsCasting && Me.Target.HasAura("Shadow Word: Pain"));
        }

    }
}

